<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/icons.css" />
	<style>
		.table tr:first-child {
			background: url(static/img/tableheader-bg.gif) no-repeat left top;
			background-color: #DCE9F2;
			border-top: 1px solid #CBD6DE;
			border-bottom: 1px solid #ADBECB;
			color: #467aa7;
			font-size: 13px;
			font-weight: bold;
		}

		.table {
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			font-size: 13px;
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			overflow: auto;
			max-height: 400px;
		}

		.table td {
			height: 40px;
			text-align: center;
			border: 1px solid #CBD6DE;
			padding: 0;
			margin: 0;
		}
	</style>
</head>

<body>
	<div class="aui-content">
		<div class="aui-content aui-content-padded" style="text-align:center;width: 72%;float:left;">
			<input type="text" placeholder="请输入物料编号/物料名称搜索" id="searchValue" />
		</div>
		<div class="aui-content aui-content-padded" style="text-align:center;width: 5%;float:left;">
			<p>
				<button type="button" class="aui-btn aui-btn-info aui-iconfont" style="font-size: 20px;"
					onclick="doSearch();">查询</button>
			</p>
		</div>
	</div>

	<div id="wrap">

		<div class="table" style="background-color:white;">
			<table id='chkHCTable' class="table" style='width:100%;'>
				<thead id="chkHCTableHead">
				</thead>
				<tbody id="chkHCTableBody">
				</tbody>
			</table>
		</div>
		<br />
	</div>
	<div class="aui-content">
		<div class="aui-content aui-content-padded" style="text-align:center;margin-bottom: 5%">
			<p>
			<div class="aui-btn aui-btn-info" onclick="doSaveHC()" style="width: 100%;height: 100%;">
				<span class="aui-iconfont" style="font-size: 26px;">确定</span>
			</div>
			</p>
		</div>

	</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>

	var HCStrs = "";
	// 传入后台的参数，用来做模糊查询使用的
	var condition = "";
	var mrlCodes = "";
	var myobj = [];
	var list = [];
	apiready = function () {
		mrlCodes = api.pageParam.mrlCodes;
		getUnExistCHKModelTaskHC(mrlCodes, condition);
	}

	/**查询框*/
	function doSearch() {
		condition = document.getElementById('searchValue').value;
		getUnExistCHKModelTaskHC(mrlCodes, condition);
	}

	function getUnExistCHKModelTaskHC(mrlCodes, condition) {
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getUnExistCHKModelTaskHC";
		var un = localStorage.getItem('un');
		// var pw = localStorage.getItem('pw');
		// var serverIp = localStorage.getItem('serverIp');
		// var serverPort = localStorage.getItem('serverPort');
		// var serverProject = localStorage.getItem('serverProject');
		// var url1 = serverIp+":"+serverPort+"/"+serverProject;

		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		params.returnAll = 'false';
		params.timeout = 60;

		var data = {
			values: {
				un: un,
				// pw: pw,
				// url: url1,
				existCodes: mrlCodes,
				condition: condition
			}
		};

		// ajaxForData(params,data,false,function(ret, err){
		// 	myobj = eval("("+ret.data+")");		
		// 	$("#chkHCTable").children().remove();
		// 	$("#chkHCTable").append("<tr id='tr2'><td width='10%' algin='center'></td><td style='display:none' algin='center'>物料主键</td><td width='10%' algin='center'>物料编号</td><td width='80%' algin='center'>物料名称</td></tr>");
		//     for (var i = 0; i < myobj.length; i++) {

		// 		var HCId = myobj[i].HCId;
		// 		var mrlGid = myobj[i].mrlGid;
		// 		var mrlCode = myobj[i].mrlCode;
		// 		var mrlName = myobj[i].mrlName;
		// 		var mrlExName = myobj[i].mrlExName;
		// 		var qty = myobj[i].qty;
		// 		var measureName = myobj[i].measureName;
		// 		var consumeType = myobj[i].consumeType;
		// 		var remark = myobj[i].remark;			
		// 		//var str = "<tr ><td width='10%' algin='center'><input id='"+HCId+"' type='checkbox' onclick='setEquipMCHKModelHC(\""+HCId+"\",\""+mrlGid+ "\",\""+mrlCode+ "\",\""+mrlName+"\",\""+consumeType+"\",\""+qty+"\",\""+remark+"\");'></td><td width='10%' algin='center'>"+mrlCode+"</td><td width='80%' algin='center'>"+mrlName+"</td></tr>"
		// 		var str = "<tr ><td width='10%' algin='center'><input id='"+HCId+"' type='checkbox' onclick='setEquipCHKHC("+i+");'></td><td width='10%' algin='center'>"+mrlCode+"</td><td width='80%' algin='center'>"+mrlName+"</td></tr>"
		// 		$("#chkHCTable").append(str);

		// 	}
		// });

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 60,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//成功
				if (myobj.code == '0') {
					//	$("#chkHCTableHead").children().remove();
					//$("#chkHCTableHead").append("<tr id='tr2'><td width='10%' algin='center'></td><td style='display:none' algin='center'>物料主键</td><td width='10%' algin='center'>物料编号</td><td width='80%' algin='center'>物料名称</td></tr>");
					var gtml5 = "<tr id='tr2'><td width='10%' algin='center'></td><td style='display:none' algin='center'>物料主键</td><td width='10%' algin='center'>物料编号</td><td width='80%' algin='center'>物料名称</td></tr>";
					$api.html($api.byId("chkHCTableHead"), gtml5);

					list = myobj.list;
					var str = "";
					if (list != undefined) {
						for (var i = 0; i < list.length; i++) {

							var HCId = list[i].HCId;
							var mrlGid = list[i].mrlGid;
							var mrlCode = list[i].mrlCode;
							var mrlName = list[i].mrlName;
							var mrlExName = list[i].mrlExName;
							var qty = list[i].qty;
							var measureName = list[i].measureName;
							var consumeType = list[i].consumeType;
							var remark = list[i].remark;
							//var str = "<tr ><td width='10%' algin='center'><input id='"+HCId+"' type='checkbox' onclick='setEquipMCHKModelHC(\""+HCId+"\",\""+mrlGid+ "\",\""+mrlCode+ "\",\""+mrlName+"\",\""+consumeType+"\",\""+qty+"\",\""+remark+"\");'></td><td width='10%' algin='center'>"+mrlCode+"</td><td width='80%' algin='center'>"+mrlName+"</td></tr>"
							str = "<tr ><td width='10%' algin='center'><input id='" + HCId + "' type='checkbox' onclick='setEquipCHKHC(" + i + ");'></td><td width='10%' algin='center'>" + mrlCode + "</td><td width='80%' algin='center'>" + mrlName + "</td></tr>"
							$("#chkHCTableHead").append(str);
							//chkHCTableBody
							//$api.html($api.byId("chkHCTableBody"), str);
						}
					} else {
						//$api.html($api.byId("chkHCTableBody"), "");
						$("#chkHCTableHead").append("");
					}
				} else if (myobj.code == '1') {
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}

	function setEquipCHKHC(i) {
		var obj = list[i];
		if ($('#' + obj.HCId).is(':checked')) {
			var id = obj.HCId.replace("\n", "");
			var mrlGid = obj.mrlGid.replace("\n", "");
			var code = obj.mrlCode.replace("\n", "");
			var name = obj.mrlName.replace("\n", "");
			var consumeType = obj.consumeType.replace("\n", "");
			var qty = obj.qty
			var remark = obj.remark.replace("\n", "");

			var str = id + ":" + mrlGid + ":" + code + ":" + name + ":" + consumeType + ":" + qty + ":" + remark;
			//判断选则的点检项是否已经选择，如果已选则删除，如果未选则添加
			if (HCStrs == "") {
				HCStrs = str;
			} else {
				HCStrs = HCStrs + "," + str;
			}

		} else {
			HCStrs = "";
		}


	}

	function doSaveHC() {
		//alert(itemStrs);	
		api.closeWin();
		console.log(HCStrs);
		api.execScript({
			// name : 'about2',
			// frameName : 'about-con',
			name: 'uemChkTask',
			script: 'setAddHC("' + HCStrs + '")'
		});
	}

</script>

</html>